package com.wq.recruit.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wq.recruit.entity.Recruit;
import com.wq.recruit.mapper.RecruitMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RecruitService {
    @Autowired
    private RecruitMapper recruitMapper;

    //    推荐职位 state 0：关闭 1:开启 2：推荐   根据发布时间降序排序，并且查询前size条数据
    public List<Recruit> findRecommend(String state, int size) {
        QueryWrapper<Recruit> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(null != state, "state", state).orderByDesc("createtime");
        Page<Recruit> recruitPage = new Page<>(1, size);
        Page<Recruit> page = recruitMapper.selectPage(recruitPage, queryWrapper);
        return page.getRecords();
    }

    //    最新职位 根据发布时间降序排序，并且查询前size条数据
    public List<Recruit> findLatest(String state, int size) {
        QueryWrapper<Recruit> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne(null != state, "state", state).orderByDesc("createtime");
        Page<Recruit> recruitPage = new Page<>(1, size);
        Page<Recruit> page = recruitMapper.selectPage(recruitPage, queryWrapper);
        return page.getRecords();
    }

}
